import { followDoctorAPI } from "@/apis/consult"
import type { Doctor, FollowType, Knowledge } from "@/types/consult"
import { ref } from "vue"

export function useFollow(type: FollowType = 'doc') {
    // 按钮加载效果
const loading = ref(false)

// 按钮点击事件
const onFollow = async (item: Doctor | Knowledge) => {
      loading.value = true
      try{
        await followDoctorAPI(item.id, type)
        // 如果likeFlag 是 1 就变成 0 ，否则就变成 1
        item.likeFlag = item.likeFlag === 1 ? 0 : 1
      }finally{
        loading.value = false
      }
    }
    return { 
        loading,
        onFollow
     }
}